<?php

class MMenu extends CI_Model {

    private $matl;
    private $mahangsx;
    
    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->OnCreate();
    }

    function OnCreate() {
        $this->matl = '';
        $this->mahangsx = '';
    }

    public function set_mahangsx($data) {
        $this->mahangsx = $data;
    }

    public function set_matl($data) {
        $this->matl = $data;
    }

    public function get_mahangsx() {
        return $this->mahangsx();
    }

    public function get_matl() {
        return $this->matl;
    }

//////////////////////////
    public function Save() {
        $data = array("mahangsx" => $this->mahangsx, "matl" => $this->matl);
        $this->db->insert("menu", $data);
    }
    public function Insert($mahangsx,$matl) {
        $data = array("mahangsx" => $mahangsx, "matl" => $matl);
        $this->db->insert("menu", $data);
    }
    public function getOject($strWhere) {
        $Query = $this->db->query("SELECT a.mahangsx, b.tenhangsx FROM menu a, hangsanxuat b WHERE a.mahangsx = b.mahangsx AND a.matl=".$strWhere." ORDER BY matl");
        return $Query->result_array();
    }
    public function UpdateField($strWhere = NULL) {
        $arr = array();
        $arr["mahangsx"] = $this->mahangsx;
        $arr["matl"] = $this->matl;
        if (!empty($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
        }
        $this->db->update("hangsanxuat", $arr);
    }

    public function Delete($strWhere = NULL) {
        if (!is_null($strWhere)) {
            $this->db->where($strWhere, NULL, FALSE);
            $this->db->delete("hangsanxuat");
        }
        else
            $this->db->empty_table('hangsanxuat');
    }
    public function get_top_id() {
        $Query = $this->db->query("select * from hangsanxuat");
        $dem = $Query->num_rows();
        return $dem + 1;
    }
    
}

?>
